/**
*      author: Y_Yao
*      created: 2024-09-21 16:59:55
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
int n,ret;

bool check(string& s,int i)
{
    string tmp = s.substr(i);
    LL a = stoll(tmp);
    for(int k = 2;k * k <= a;k++)
    {
        if(a % k == 0)
            return false;
    }
    return true;
}

void dfs(string& s,int i)
{
    char a = s[i];
    if(i <= 3)//年
    {
        if(a == '-')
        {
            for(int k = 0;k < 10;k++)
            {
                s[i] = k + '0';
                dfs(s,i);
                s[i] = '-';
            }
        }
        else dfs(s,i+1);
    }
    else if(i == 4)//月的十位
    {
        if(a == '-')
        {
            for(int k = 0;k < 2;k++)
            {
                s[i] = k + '0';
                dfs(s,i);
                s[i] = '-';
            }
        }
        else dfs(s,i+1);
    }
    else if(i == 5)//月的个位
    {
        if(s[i-1] == '1' && a == '-')
        {
            for(int k = 0;k <= 2;k++)
            {
                s[i] = k + '0';
                dfs(s,i);
                s[i] = '-';
            }
        }
        else if(s[i-1] == '0' && a == '-')
        {
            for(int k = 0;k < 10;k++)
            {
                s[i] = k + '0';
                dfs(s,i);
                s[i] = '-';
            }
        }
        else dfs(s,i+1);
    }
    else if(i == 6)//天的个位
    {
        int year = stoi(s.substr(0,4));
        int month = stoi(s.substr(4,2));
        
    }
}

void solve()
{
    string s;
    cin >> s;
    n = s.size();
    dfs(s,0);
    cout<<ret<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
        ret = 0;
    }
    return 0;
}